package com.yitong.equipment.ui.mine

import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.BarUtils
import com.yitong.equipment.R
import com.yitong.equipment.base.BaseFragment
import com.yitong.equipment.databinding.FragmentMineBinding
import com.yitong.equipment.entity.other.MineConfigBean
import com.yitong.equipment.entity.other.MineConfigColumnBean
import com.yitong.equipment.ext.init
import com.yitong.equipment.ui.adapter.MineAdapter
import com.yitong.equipment.ui.viewmodel.MineViewModel
import com.yitong.equipment.view.MineHeaderView
import java.util.ArrayList

class MineFragment : BaseFragment<MineViewModel, FragmentMineBinding>() {

    //我的学习
    val one_on_one = "one_on_one" //线上培训
    val training_offline = "training_offline" //线下培训
    val sponsor_learn = "sponsor_learn" //发起学习
    val study_record = "study_record" //学习足迹

    //我的园所
    val school_manage = "school_manage" //园所管理
    val data_report = "data_report" //数据报表

    //设置
    val account_setting = "account_setting" //账号设置
    val soft_setting = "soft_setting" //软件设置
    val vip_service = "vip_service" //在线客服

    private var columnList: List<MineConfigBean>? = null
    private var mineHeaderView: MineHeaderView? = null
    private var mineAdapter: MineAdapter? = null

    override fun setContent(): Int {
        return R.layout.fragment_mine
    }

    override fun initView() {
        bindingView.ll?.setPadding(0, BarUtils.getStatusBarHeight(), 0, 0)
    }

    override fun firstLoad() {
        mineHeaderView = context?.let { MineHeaderView(it) }
        columnList = getMineConfigData()
        mineAdapter = MineAdapter(columnList as MutableList<MineConfigBean>?)
        mineHeaderView?.let { mineAdapter!!.addHeaderView(it) }
        bindingView.recycleView.init(LinearLayoutManager(activity), mineAdapter!!, false)
        bindingView.refreshLayout.setEnableLoadMore(false)
        bindingView.refreshLayout.setEnableRefresh(false)
    }

    private fun getMineConfigData(): List<MineConfigBean> {
        val result: MutableList<MineConfigBean> = ArrayList()
        getStudyConfig()?.let { result.add(it) }
        getNoteConfig()?.let { result.add(it) }
        getSettingConfig()?.let { result.add(it) }
        return result
    }

    private fun getStudyConfig(): MineConfigBean? {
        val groupName = "我的学习"
        val columnList: MutableList<MineConfigColumnBean> = ArrayList<MineConfigColumnBean>()
        columnList.add(MineConfigColumnBean("线上培训", R.mipmap.mine_icon_online_nor, one_on_one, isRequireUser = true, isRequireGroup = true))
        columnList.add(MineConfigColumnBean("线下培训", R.mipmap.mine_icon_offline_nor, training_offline, isRequireUser = true, isRequireGroup = true))
        columnList.add(MineConfigColumnBean("发起学习", R.mipmap.mine_icon_study_nor, sponsor_learn, isRequireUser = true, isRequireGroup = true))
        columnList.add(MineConfigColumnBean("学习足迹", R.mipmap.mine_icon_track_nor, study_record, isRequireUser = true, isRequireGroup = true))
        return MineConfigBean(groupName, 0, groupName, columnList)
    }

    private fun getNoteConfig(): MineConfigBean? {
        val groupName = "我的园所"
        val columnList: MutableList<MineConfigColumnBean> = ArrayList<MineConfigColumnBean>()
        columnList.add(MineConfigColumnBean("园所信息", R.mipmap.mine_icon_management_nor, school_manage, isRequireUser = true, isRequireGroup = true))
        columnList.add(MineConfigColumnBean("数据报表", R.mipmap.mine_icon_data_nor, data_report, isRequireUser = true, isRequireGroup = true))
        return MineConfigBean(groupName, 0, groupName, columnList)
    }

    private fun getSettingConfig(): MineConfigBean? {
        val groupName = "设置"
        val columnList: MutableList<MineConfigColumnBean> = ArrayList<MineConfigColumnBean>()
        columnList.add(MineConfigColumnBean("账号设置", R.mipmap.mine_icon_account_nor, account_setting, isRequireUser = true, isRequireGroup = false))
        columnList.add(MineConfigColumnBean("软件设置", R.mipmap.mine_icon_setting_nor, soft_setting, isRequireUser = false, isRequireGroup = false))
        columnList.add(MineConfigColumnBean("在线客服", R.mipmap.mine_icon_service_nor, vip_service, isRequireUser = false, isRequireGroup = false))
        return MineConfigBean(groupName, 0, groupName, columnList)
    }


}